package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.domain.News;
import com.example.mybatisplus.mapper.NewsMapper;
import com.example.mybatisplus.model.domain.Report;
import com.example.mybatisplus.model.domain.Userlist;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.NewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2023-01-06
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Autowired
    private NewsService newsService;

    @Override
    public void news(News news) {
        Userlist curUser = SessionUtils.getCurUser();
        news.setName(curUser.getName())
                .setLevel(curUser.getLevel())
                .setTitle(news.getTitle())
                .setContent(news.getContent());
        newsService.save(news);
    }

    @Override
    public Page<News> pageList(News news, PageDTO pageDTO) {
        Page<News> page = new Page<>(pageDTO.getPageNo(),pageDTO.getPageSize());
        QueryWrapper<News> wrapper=new QueryWrapper<>();
        if (StringUtils.isNotBlank(news .getLevel())){
            wrapper.like("level",news.getLevel());
        }
        newsMapper.selectPage(page,wrapper);
        return page;
    }


}
